#ifndef ENTITY_H
#define ENTITY_H

//#include <utils/DynamicClass.h>

#include <utils/String.h>
#include <utils/Maths.h>
#include <core/IRenderer.h>
#include <concrete/Physics.h>
/*
class EntityComponent
{
public:
	//Called when the parent entity is initialised
	virtual void init() = 0;
	//Called when the parent entity 
	virtual void update() = 0;
};

class DrawComponent
{
	
public:
	virtual void init( Entity* pParent )
	{
		pParent->addSharedVar<Point>( "Point" );
	}
	virtual void update( Entity* pParent )
	{
		
	}
};
*/
class Entity
{
	String m_sName;
	
	//std::list<EntityComponent> m_Components;
	
public:
	Entity( String sName ) : m_sName(sName) {}
	
	virtual void update() {}
	
};
/*
class IDrawable
{
public:
	virtual Point* getPoint() = 0;
	virtual void   draw( IRenderer* pRenderer ) = 0;
};

class IPhysical
{
public:	
	virtual PhysicsPoint* getPhysicsPoint() = 0;
	virtual void          update() = 0;
};
*/
class VisibleEntity : public Entity
{
	String        m_sName;
	PhysicsPoint* m_pPoint;
	GfxModel*     m_pModel;
	//GfxModel m_Model;
public:
	/*
	VisibleEntity( String sName, Vector vPos, Scalar fAngle=0 ) : Entity(sName)
	{
		addVar( "PhysicsPoint", (PhysicsPoint*)NULL ) = new PhysicsPoint(vPos);
		addHardVar( "pModel", &m_pModel );
		addVar( "pModel", &m_pModel );
	}
	*/
	
	//Copy constructor
	VisibleEntity( const VisibleEntity& source ) : Entity( source.m_sName )
	{
		m_pPoint = new PhysicsPoint( *source.m_pPoint );
		m_pModel = new GfxModel( *source.m_pModel );
	}
	
	VisibleEntity& operator=( const VisibleEntity& other )
	{
		PhysicsPoint* pPoint = new PhysicsPoint( *other.m_pPoint );
		GfxModel*     pModel = new GfxModel( *other.m_pModel );
		delete m_pModel;
		delete m_pPoint;
		m_pPoint = pPoint;
		m_pModel = pModel;
		
		m_sName = other.m_sName;
	}	
	
	VisibleEntity( String sName, Vector vPos, Scalar fAngle=0 ) : Entity(sName)
	{
		m_pPoint = new PhysicsPoint( vPos );
		m_pModel = new GfxModel();
	}
	virtual ~VisibleEntity()
	{
		delete m_pModel;
		delete m_pPoint;
	}
	
	PhysicsPoint*    getPoint() { return m_pPoint; }
	GfxModel* getModel() { return m_pModel; }
	
	virtual void draw( IRenderer* pRenderer )
	{
		if ( !m_pModel ) {
			std::cout << "Error in VisibleEntity::draw( ): Model instance does not exist." << std::endl;
			return;
		}
		pRenderer->drawGfxModel( *m_pModel );
	}
	
	virtual void update()
	{
		m_pPoint->update( 1.0 );
	}
	
};

/*class Entity : public DynamicClass
{
public:
	Entity() : DynamicClass() {}
	Entity(String sType, String sName) : DynamicClass(sType) { addVar<String>("name", sName); }
	Entity* clone() { return static_cast<Entity*>(DynamicClass::clone()); }

};*/

#endif
